/**

 * @author LinYiSong

 */

$(function(){

	CKEDITOR.replace('remarks');

	$("#code").blur(function() {
		var code = $("#code").val();
		if(code!=''){
			ProductServImpl.searchByCode(code, callback);
		}
	})

	//表单验证
    $('.form').validate({
        rules: {
            code: {
                required: true
            },
            name: {
                required: true,
            },
            price: {
                required: true,
                digits: true
            },
            salesPrice: {
                required: true,
                digits:true,
            },
            floatPrice: {
                required: true,
                digits:true,
            },
            company: {
                required: true,
            },
        },
        messages: {
            code: {
                required: '名字不能为空'
            },
            name: {
                required: '必填',
            },
            price: {
                required: '必填',
            },
            salesPrice: {
                required: '必填',
            },
            floatPrice:{
            	required: '必填',
            },
            company: {
                required: "必填",
            },
        }
    });
    /* 设置默认属性 */
    $.validator.setDefaults({
        submitHandler: function(form){
            form.submit();
        }
    });

});

function callback(msg) {
	if (msg != "") {
		alert("该编号已存在");
		$("#code").focus();
	}	
}
